<script lang="ts" setup>
import type { UserStructure } from "@/api/user.ts"

const editData = ref({
  username: "",
  password: "123456",
  email: "",
  phone: ""
})

const { data } = defineProps({
  data: {
    type: Object as PropType<UserStructure>,
    default: () => {
      return {}
    }
  },
  type: {
    type: Number,
    required: true
  }
})

watchEffect(() => {
  if (data) {
    editData.value = { ...data }
  }
})

const emit = defineEmits(["submit"])
const handleSubmit = () => {
  emit("submit", editData.value)
}
</script>

<template>
  <el-form :model="editData" label-width="auto" style="max-width: 600px">
    <el-form-item label="昵称">
      <el-input v-model="editData.username" placeholder="请输入昵称"></el-input>
    </el-form-item>
    <el-form-item label="密码">
      <el-input v-model="editData.password" placeholder="请输入密码"></el-input>
    </el-form-item>
    <el-form-item label="电话">
      <el-input v-model="editData.phone" placeholder="请输入电话"></el-input>
    </el-form-item>
    <el-form-item label="邮箱">
      <el-input v-model="editData.email" placeholder="请输入邮箱"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="handleSubmit">保存</el-button>
    </el-form-item>
  </el-form>
</template>

<style scoped></style>
